package com.yunkeji.api.moments.controller;

import com.yunkeji.api.moments.bo.MomentsListBo;
import com.yunkeji.api.moments.bo.MomentsReplyBo;
import com.yunkeji.api.moments.bo.PubMomentsBo;
import com.yunkeji.api.moments.bo.ReplyListBo;
import com.yunkeji.api.moments.service.MomentsService;
import com.yunkeji.api.moments.vo.MomentsListVo;
import com.yunkeji.api.moments.vo.ReplyVo;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.dao.domain.BaseId;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.concurrent.TimeUnit;

/**
 * 朋友圈动态相关接口
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/moments")
public class MomentsController extends BaseController {

    private final MomentsService momentsService;

    /**
     * 获取动态列表-推荐,关注,我的,他人的
     *
     * @author 老张
     */
    @PostMapping("/momentsList")
    public TableDataInfo<MomentsListVo> momentsList(@Valid @RequestBody MomentsListBo bo) {
        return momentsService.momentsList(bo);
    }

    /**
     * 获取动态的回复列表
     *
     * @author 老张
     */
    @PostMapping("/replyList")
    public TableDataInfo<ReplyVo> replyList(@RequestBody @Valid ReplyListBo bo) {
        return momentsService.replyList(bo);
    }

    /**
     * 获取动态的回复列表-的回复详情
     *
     * @author 老张
     */
    @PostMapping("/replyDetailList")
    public TableDataInfo<ReplyVo> replyDetailList(@RequestBody @Valid ReplyListBo bo) {
        return momentsService.replyDetailList(bo);
    }

    /**
     * 发布动态
     *
     * @author 老张
     */
    @PostMapping("/pubMoments")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R pubMoments(@RequestBody PubMomentsBo pubMomentsBo) {
        momentsService.pubMoments(pubMomentsBo);
        return R.ok();
    }

    /**
     * 删除动态
     *
     * @author 老张
     */
    @PostMapping("/delMoments")
    public R delMoments(@RequestBody BaseId baseId) {
        momentsService.delMoments(baseId);
        return R.ok();
    }

    /**
     * 删除回复
     *
     * @author 老张
     */
    @PostMapping("/delReply")
    public R delReply(@RequestBody BaseId baseId) {
        momentsService.delReply(baseId);
        return R.ok();
    }
    /**
     * 回复-动态
     *
     * @author 老张
     */
    @PostMapping("/replyMoments")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R replyMoments(@Valid @RequestBody MomentsReplyBo bo) {
        momentsService.replyMoments(bo);
        return R.ok();
    }

    /**
     * 回复-回复
     *
     * @author 老张
     */
    @PostMapping("/replyReply")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R replyReply(@Valid @RequestBody MomentsReplyBo bo) {
        momentsService.replyReply(bo);
        return R.ok();
    }

    /**
     * 点赞,取消点赞-动态
     *
     * @author 老张
     */
    @PostMapping("/likeMoments")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    public R likeMoments(@RequestBody BaseId baseId) {
        momentsService.likeMoments(baseId);
        return R.ok();
    }

    //    /** 点赞,取消点赞-回复 */
    //    @PostMapping("/likeReply")
    //    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快")
    //    public R likeReply(@RequestBody BaseId baseId) {
    //        momentsService.likeReply(baseId);
    //        return R.ok();
    //    }

}
